<?php
class Endereco extends CI_Model {

	public function  __construct ( ) {
		$this->load->database();
	}
	
	
	public function salvar($endereco, $id=null){
	
		if($id==null){
			if($this->db->insert('endereco', $endereco)){
				return $this->db->insert_id();
			}
		}
		else{
			$this->db->where('end_id', $id);
			$this->db->update('endereco', $endereco);
			return $id;
		}
		return false;
	}
	
	
	public function buscar($busca){
		$query = $this->db->get_where('endereco',$busca);
		if ($query->num_rows()>1)
			return $query->result_array();
		if ($query->num_rows()==1)
			return $query->row_array();
		return false;
	}
	
}